<?php
include_once('admin_global.php');
bn_include_lib('bn_jquery');
$gf=new bn_genralfunc();
$gad=new bn_gadget();
$page=new bn_page();
$theme->add_block('body');

$theme->add_script(jquery_element('#clear','click','
$("#title").val("");
$("#row_id").val("");
$(".editor").val("");
$("#page_gadget :selected").removeAttr("selected");
'));

$theme->add_script(jquery_element('#submit','click','
var tit=$("#title").val();
var rid=$("#row_id").val();
var txt=$(".editor").val();
var gad=$("#page_gadget :selected").val();
$.post(window.location.href,{cmd:"post",title:tit,rowid:rid,text:txt,gadget:gad},function(data){
$("#show").html(data); 
$("#row_id").val("");   
});'));

$cmd=$_POST['cmd'];
$row=new stdclass;
if(isset($cmd))
{
   extract($_POST);
   if($cmd=='post')
   {
    if(is_null($gadget))
    $gadget='';
    if($rowid=='')
    $page->insert($title,$text,'disable',$gadget);
    else
    $page->update($title,$text,'',$gadget,$rowid);
   }
   if($cmd=='update')
   $row=$page->get_page($id)->fetchOBJ();
}
?>
<div id="page_div">
<table>
<tr>
	<td><?php echo $lang[64] ?></td>
	<td><input type="text" size="100" autocomplete="on" name="title" id="title" class="input-text" value="<?= $row->title ?>"/></td>
</tr>
<tr>
	<td colspan="2"><?php echo $lang[65] ?><br />
	<?php $gf->editor($theme,$row->text); ?></td>
</tr>
<tr>
	<td><?php echo $lang[66] ?></td>
	<td><?php $gad->list_page_gadget(array('name' => 'plist_gadget','cssclass' => 'select','selected'=>$row->gadget)); ?></td>
</tr>
<tr>
	<td colspan="2">
    <input type="submit" name="submit" id="submit" value="<?php echo $lang[15] ?>" class="button"/>
    <input type="submit" name="clear" id="clear" value="<?php echo $lang[17] ?>" class="button"/>
    </td>
</tr>
</table>
<input type="hidden" name="row_id" id="row_id" value="<?= $row->id ?>"/>
</div>
<?php
$theme->render();
?>